package com.ruoyi.web.controller.system;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.system.domain.DTO.LegalAidLawyerDTO;
import com.ruoyi.system.domain.LegalAidLawyer;
import com.ruoyi.system.domain.vo.LegalAidLawyerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ILegalAidLawyerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 律师信息Controller
 * 
 * @author ruoyi
 * @date 2023-08-09
 */
@RestController
@RequestMapping("/system/lawyer")
@Api(tags = "律师管理")
@Slf4j
public class LegalAidLawyerController extends BaseController
{
    @Autowired
    private ILegalAidLawyerService legalAidLawyerService;

    /**
     * 查询律师信息列表
     * @param legalAidLawyerDTO
     * @return
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:list')")
    @GetMapping("/list")
    @ApiOperation("查询律师信息列表")
    @Anonymous
    public TableDataInfo list(LegalAidLawyerDTO legalAidLawyerDTO)
    {
//        startPage();
        List<LegalAidLawyerVO> list = legalAidLawyerService.selectLegalAidLawyerList(legalAidLawyerDTO);
        return getDataTable(list);

    }
    /**
     * 导出律师信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:export')")
    @Log(title = "律师信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LegalAidLawyerDTO legalAidLawyerDTO)
    {
        List<LegalAidLawyerVO> list = legalAidLawyerService.selectLegalAidLawyerList(legalAidLawyerDTO);
        ExcelUtil<LegalAidLawyer> util = new ExcelUtil<LegalAidLawyer>(LegalAidLawyer.class);
//        util.exportExcel(response, list, "律师信息数据");
    }

    /**
     * 根据id获取律师信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        log.info("根据id查询律师信息：{}",id);
        LegalAidLawyerVO legalAidLawyerVO = legalAidLawyerService.selectLawyerWithUserById(id);
        return success(legalAidLawyerVO);
    }

    /**
     * 新增律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:add')")
    @Log(title = "律师信息", businessType = BusinessType.INSERT)
    @ApiOperation("新增律师信息")
    @PostMapping
    public AjaxResult add(@RequestBody LegalAidLawyerDTO legalAidLawyerDTO)
    {
        logger.info("legalAidLawyerDTO====="+legalAidLawyerDTO);
     legalAidLawyerService.insertLegalAidLawyer(legalAidLawyerDTO);
      return AjaxResult.success();
    }

    /**
     * 修改律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:edit')")
    @Log(title = "律师信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LegalAidLawyerDTO legalAidLawyerDTO)
    {
        log.info("律师详细信息：{}",legalAidLawyerDTO);
         legalAidLawyerService.updateWithUser(legalAidLawyerDTO);
         return AjaxResult.success();
    }

    /**
     * 删除律师信息
     */
    @PreAuthorize("@ss.hasPermi('system:lawyer:remove')")
    @Log(title = "律师信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
//        return toAjax(legalAidLawyerService.deleteLegalAidLawyerByIds(ids));
        log.info("ids:{}",ids);
        legalAidLawyerService.deleteLegalAidLawyerWithUserByIds(ids);
        return AjaxResult.success();
    }
}
